package cn.aezo.minions.gen.mapper;

import cn.aezo.minions.gen.model.ProjectModule;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created by smalle on 2017/10/28.
 */
public interface ProjectModuleDao {
    @Select("select * from project_module where project_module_id = #{projectModuleId}")
    ProjectModule findOne(Long projectModuleId);

    @Select("select * from project_module where module_name = '"+ ProjectModule.DefaultModuleName +"'")
    ProjectModule getDefaultModule();

    @Select("select * from project_module where project_config_id = #{projectConfigId}")
    List<ProjectModule> findByProjectConfigId(Long projectConfigId);

    @Insert("insert into project_module(project_config_id, module_name, module_name_cn, control_mapping_uri) " +
            "values(#{projectConfigId}, #{moduleName}, #{moduleNameCn}, #{controlMappingUri})")
    int insert(ProjectModule projectModule);

    @Insert("update project_module set module_name = #{moduleName}, module_name_cn = #{moduleNameCn}, control_mapping_uri = #{controlMappingUri} " +
            " where project_module_id = #{projectModuleId}")
    int update(ProjectModule projectModule);

    @Delete("delete from project_module where project_module_id = #{projectModuleId}")
    int delete(Long projectModuleId);

    @Delete("delete from project_module where project_config_id = #{projectConfigId}")
    int deleteByProjectConfigId(Long projectConfigId);
}
